<html>
<head>
<script>
var url='';
var title='';
var msgSig="\n\n(via *Buzz My Selection* extension)";
var showSignature= localStorage.getItem("storageKeyShowSig");

chrome.browserAction.onClicked.addListener(function(tab) {
	title=tab.title;
	url=tab.url;
	chrome.tabs.executeScript(null, {file: "content_script.js"});
});

chrome.extension.onConnect.addListener(function(port) {
        if (port.name != 'buzzmyselection')
            return;
        port.onMessage.addListener(function(data) {
            if (data.command == "postBuzz") {
                postBuzz(data.selection);
            } 
        });
});

function postBuzz(selection){
var msg = selection;
if(localStorage.getItem("storageKeyShowSig")==0)
msg+=msgSig;

var win=window.open("http://www.google.com/buzz/post?message="+encodeURIComponent(msg)+"&url="+url+"&title="+encodeURIComponent(title), "_blank", "resizable=0, scrollbars=0, width=690, height=415" );
	
win.moveTo(80,80);
	
win.focus();

}

chrome.extension.onRequest.addListener(function(req,sender,response) {
	if(req.type == 'getshowSignature'){
		response(showSignature);
	} else if(req.type == 'setshowSignature'){
		if(req.value){
			localStorage.setItem("storageKeyShowSig","1");
			showSignature=true;
		}else{
			localStorage.setItem("storageKeyShowSig","0");
			showSignature=false;
		}
	}
});
</script>

</head>

</html>
